import java.util.Scanner;

public class p5728 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[][] scores = new int[N][3];
        for (int i = 0; i < N; i++) {
            scores[i][0] = scanner.nextInt();
            scores[i][1] = scanner.nextInt();
            scores[i][2] = scanner.nextInt();
        }

        int count = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                boolean isEachSubjectOK = true;
                for (int k = 0; k < 3; k++) {
                    if (Math.abs(scores[i][k] - scores[j][k]) > 5) {
                        isEachSubjectOK = false;
                        break;
                    }
                }
                if (isEachSubjectOK) {
                    int totalScoreI = scores[i][0] + scores[i][1] + scores[i][2];
                    int totalScoreJ = scores[j][0] + scores[j][1] + scores[j][2];
                    if (Math.abs(totalScoreI - totalScoreJ) <= 10) {
                        count++;
                    }
                }
            }
        }
        System.out.println(count);

        scanner.close();
    }
}
